package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.experiment.ExperimentDetail;
import com.siwei.mes.service.experiment.ExperimentDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 试验台账json详情相关
 *
 * @author linzi
 * @since 2023-12-27 23:30:46
 */
@Api(value = "试验台账json详情")
@RestController
@RequestMapping("experimentDetail")
public class ExperimentDetailController {
    @Resource
    private ExperimentDetailService experimentDetailService;

    @ApiOperation(value = "新增试验台账json详情")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) ExperimentDetail entity) {
        return Json.succ().data(ApiResult.addColumn("id", experimentDetailService.create(entity)));
    }

    @ApiOperation(value = "修改试验台账json详情")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) ExperimentDetail entity) {
        experimentDetailService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除试验台账json详情")
    @PostMapping("/delete")
    public Json delete(@RequestBody ExperimentDetail entity) {
        experimentDetailService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取试验台账json详情")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<ExperimentDetail, ExperimentDetail> query) {
        return Json.succ().data(experimentDetailService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取试验台账json详情")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(experimentDetailService.loadById(id));
    }

    @ApiOperation(value = "获取所有试验台账json详情")
    @PostMapping("getAll")
    public Json getAll(@RequestBody ExperimentDetail entity) {
        return Json.succ().data(ApiResult.addList(experimentDetailService.getAll(entity)));
    }

}
